#ifndef SERIALPORT_HPP_
#define SERIALPORT_HPP_

#include <boost/asio.hpp>
#include <boost/asio/serial_port.hpp>
#include <boost/bind.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/thread.hpp>
#include <boost/thread/thread.hpp>

#include "Packet.hpp"

#include <string>
#include <vector>

using boost::shared_ptr;
using boost::asio::serial_port;
using boost::asio::io_service;
using boost::system::error_code;

using std::string;
using std::vector;


#define SERIAL_PORT_READ_BUF_SIZE 256

class SerialPort {

    typedef shared_ptr<serial_port> serial_port_ptr;

protected:


private:
    io_service io_service_;
    serial_port_ptr port_;
    SerialPort(const SerialPort &p);
    SerialPort &operator=(const SerialPort &p);
    boost::shared_ptr<Packet> * Packet_RXD_ptr;
    void async_read();
    void on_receive(const error_code& ec, size_t bytes_transferred);

    char read_buf_raw_[SERIAL_PORT_READ_BUF_SIZE];

public:
    SerialPort(void);
    ~SerialPort(void);


    bool start(const char *com_port_name, int baud_rate=9600);
    void stop();

    int write(const unsigned char buf);
    int write(const unsigned char buf, const unsigned char size);

    void set_packet_rxd_ptr(boost::shared_ptr<Packet> * Packet_RXD_ptr);

protected:

};


#endif /* SERIALPORT_HPP_ */
